import { reactive } from "vue";
import { getUserByPositionApi } from "@/api/managementCenter/departmentPersonnel";
import { getCustomerSelectList } from "@/api/managementCenter/customerManagement";
import { insuranceCompanyApi } from "@/api/insuranceCompany";

export const searchItemList: Array<SuperSearch.SearchItem> = [
  {
    type: "input",
    label: "运单号",
    keyName: "waybillNumList"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "业务员",
    keyName: "bizIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "4", status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  {
    type: "dict-select",
    label: "运单类型",
    keyName: "addressTypeList",
    lookupCode: "WAYBILL_TYPE",
    optConfig: {
      label: "name",
      value: "code"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  },

  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "客户简称",
    keyName: "customerIdList",
    optionsRequest: getCustomerSelectList,
    optReqParams: { isFilterChild: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    attrs: {
      mode: "multiple"
    },
    optConfig: {
      label: "shortName",
      value: "id"
    },
    options: []
  }),

  {
    type: "input",
    label: "保单号",
    keyName: "orderNoList"
  },

  {
    type: "dict-select",
    label: "保险类型",
    keyName: "insuranceTypeList",
    lookupCode: "INSURANCE_TYPE",
    optConfig: {
      label: "name",
      value: "code"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "保险公司",
    keyName: "insuranceCompanyIdList",
    optionsRequest: insuranceCompanyApi,
    optReqParams: { pageNum: 1, pageSize: 9999, total: 1 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    attrs: {
      mode: "multiple"
    },
    optConfig: {
      label: "name",
      value: "id"
    },
    options: []
  })
];

export const tableColumnMap: Base.GeneraDataType<Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem>> = {
  "1": [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "140"
    },
    {
      field: "customerName",
      title: "客户简称",
      minWidth: "120"
    },
    {
      field: "insuranceNature",
      title: "保险性质",
      minWidth: "90",
      renderSlot: "insuranceNature"
    },
    {
      field: "insuranceType",
      title: "保险类型",
      minWidth: "90",
      renderSlot: "insuranceType"
    },
    {
      field: "insuranceCompanyName",
      title: "保险公司",
      minWidth: "120"
    },
    {
      field: "insuranceAmount",
      title: "投保货值",
      minWidth: "120"
    },

    {
      field: "insuranceRemark",
      title: "保险备注",
      minWidth: "120"
    },
    {
      field: "channelName",
      title: "渠道名称",
      minWidth: "160"
    },
    {
      field: "countryRegionName",
      title: "目的地",
      minWidth: "70"
    },

    {
      field: "outWarehouseBrokerName",
      title: "出仓代理",
      minWidth: "80"
    },
    {
      field: "channelAllocationName",
      title: "渠道类型",
      minWidth: "70"
    },
    {
      field: "itemNumber",
      title: "货件数",
      minWidth: "80"
    },
    {
      field: "actualWeight",
      title: "实重/kg",
      minWidth: "80"
    },
    {
      field: "declaredValue",
      title: "申报价值",
      minWidth: "80"
    },

    {
      field: "customerRemark",
      title: "客户保险备注",
      minWidth: "100"
    },
    {
      field: "shipmentCreateTime",
      title: "创建时间",
      minWidth: "140",
      formatter: "formatDate"
    },
    {
      field: "createTime",
      title: "下单时间",
      minWidth: "140",
      formatter: "formatDate"
    },
    {
      field: "addressType",
      title: "运单类型",
      minWidth: "110",
      renderSlot: "addressType"
    },
    {
      field: "action",
      title: "操作",
      minWidth: "150",
      renderSlot: "action",
      fixed: "right"
    }
  ],
  "2": [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "140"
    },
    {
      field: "orderNo",
      title: "保单号",
      minWidth: "120"
    },
    {
      field: "customerName",
      title: "客户简称",
      minWidth: "120"
    },
    {
      field: "insuranceNature",
      title: "保险性质",
      minWidth: "90",
      renderSlot: "insuranceNature"
    },
    {
      field: "insuranceType",
      title: "保险类型",
      minWidth: "90",
      renderSlot: "insuranceType"
    },
    {
      field: "insuranceCompanyName",
      title: "保险公司",
      minWidth: "120"
    },
    {
      field: "premium",
      title: "保费",
      minWidth: "90"
    },
    {
      field: "insuranceAmount",
      title: "投保货值",
      minWidth: "120"
    },
    {
      field: "insuranceRemark",
      title: "保险备注",
      minWidth: "120"
    },
    {
      field: "buyInsuranceTime",
      title: "保险购买时间",
      minWidth: "120",
      formatter: "formatDate"
    },
    {
      field: "channelName",
      title: "渠道名称",
      minWidth: "160"
    },
    {
      field: "countryRegionName",
      title: "目的地",
      minWidth: "70"
    },
    {
      field: "outWarehouseBrokerName",
      title: "出仓代理",
      minWidth: "80"
    },
    {
      field: "channelAllocation",
      title: "渠道类型",
      minWidth: "70"
    },
    {
      field: "itemNumber",
      title: "货件数",
      minWidth: "120"
    },
    {
      field: "actualWeight",
      title: "实重/kg",
      minWidth: "80"
    },
    {
      field: "declaredValue",
      title: "申报价值",
      minWidth: "80"
    },
    {
      field: "customerRemark",
      title: "客户备注",
      minWidth: "80"
    },
    {
      field: "applyName",
      title: "审核人",
      minWidth: "80"
    },
    {
      field: "applyTime",
      title: "审核时间",
      minWidth: "140",
      formatter: "formatDate"
    },
    {
      field: "shipmentCreateTime",
      title: "创建时间",
      minWidth: "140",
      formatter: "formatDate"
    },
    {
      field: "createTime",
      title: "下单时间",
      minWidth: "140",
      formatter: "formatDate"
    },
    {
      field: "addressType",
      title: "运单类型",
      minWidth: "110",
      renderSlot: "addressType"
    },
    {
      field: "action",
      title: "操作",
      minWidth: "180",
      renderSlot: "action",
      fixed: "right"
    }
  ],
  "3": [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "140"
    },
    {
      field: "orderNo",
      title: "保单号",
      minWidth: "120"
    },
    {
      field: "customerName",
      title: "客户简称",
      minWidth: "120"
    },
    {
      field: "insuranceNature",
      title: "保险性质",
      minWidth: "90",
      renderSlot: "insuranceNature"
    },
    {
      field: "insuranceType",
      title: "保险类型",
      minWidth: "90",
      renderSlot: "insuranceType"
    },
    {
      field: "insuranceCompanyName",
      title: "保险公司",
      minWidth: "120"
    },
    {
      field: "insuranceAmount",
      title: "投保货值",
      minWidth: "120"
    },
    {
      field: "insuranceRemark",
      title: "保险备注",
      minWidth: "120"
    },
    {
      field: "buyInsuranceTime",
      title: "保险购买时间",
      minWidth: "120",
      formatter: "formatDate"
    },
    {
      field: "channelName",
      title: "渠道名称",
      minWidth: "160"
    },
    {
      field: "countryRegionName",
      title: "目的地",
      minWidth: "70"
    },
    {
      field: "outWarehouseBrokerName",
      title: "出仓代理",
      minWidth: "80"
    },
    {
      field: "channelAllocation",
      title: "渠道类型",
      minWidth: "70"
    },
    {
      field: "itemNumber",
      title: "货件数",
      minWidth: "120"
    },
    {
      field: "actualWeight",
      title: "实重/kg",
      minWidth: "80"
    },
    {
      field: "declaredValue",
      title: "申报价值",
      minWidth: "80"
    },
    {
      field: "customerRemark",
      title: "客户备注",
      minWidth: "80"
    },
    {
      field: "applyName",
      title: "审核人",
      minWidth: "80"
    },
    {
      field: "applyTime",
      title: "审核时间",
      minWidth: "140",
      formatter: "formatDate"
    },
    {
      field: "shipmentCreateTime",
      title: "创建时间",
      minWidth: "140",
      formatter: "formatDate"
    },
    {
      field: "createTime",
      title: "下单时间",
      minWidth: "140",
      formatter: "formatDate"
    },
    {
      field: "addressType",
      title: "运单类型",
      minWidth: "110",
      renderSlot: "addressType"
    },
    {
      field: "action",
      title: "操作",
      minWidth: "120",
      renderSlot: "action",
      fixed: "right"
    }
  ]
};
